package algorithm;

public class leetcode_0012 {
    public String intToRoman(int num) {
        String s="";
        int number=num/1000;
        for(int i=0;i<number;++i){
            s+='M';
        }
        num=num-number*1000;
        number=(num)/100;
        if(number==9){
            s+="CM";
        }
        else if(number>=5){
            s+='D';
            for(int i=0;i<number-5;++i){
                s+='C';
            }
        }
        else if(number==4){
            s+="CD";
        }
        else{
            for(int i=0;i<number;++i) s+='C';
        }
        num=num-number*100;
        number=(num)/10;
        if(number==9){
            s+="XC";
        }
        else if(number>=5){
            s+='L';
            for(int i=0;i<number-5;++i){
                s+='X';
            }
        }
        else if(number==4){
            s+="XL";
        }
        else{
            for(int i=0;i<number;++i) s+='X';
        }
        num=num-number*10;
        number=(num);
        if(number==9){
            s+="IX";
        }
        else if(number>=5){
            s+='V';
            for(int i=0;i<number-5;++i){
                s+='I';
            }
        }
        else if(number==4){
            s+="IV";
        }
        else{
            for(int i=0;i<number;++i) s+='I';
        }
        return s;
    }

}
